package gui.panel_new.evaluation.student;

import enums.ExtensionEnum;
import enums.PremisaTypeEnum;
import enums.TextBundleEnum;
import enums.URLEnum;
import gui.panel_new.evaluation.exeptions.ExerciseNotBuiltException;
import gui.panel_new.evaluation.exeptions.PunctuationZeroException;
import j_util.Utiles;
import misc.BundlesProvider;
import model.Premisa;
import model.Sylogism;
import model.eval.TestExcercise;

import javax.swing.*;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
/**
 * @author Jose Martin Rozanec;
 */
public class SylogismReducirModosPanel extends ExercisePanel {
    private javax.swing.JComboBox combo1;
    private javax.swing.JComboBox combo2;
    private javax.swing.JComboBox combo3;

    private javax.swing.JTextField conclusionField;
    private javax.swing.JLabel conclusionLabel;
    private javax.swing.JLabel convertirEnLabel;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextField premisaMayorField;
    private javax.swing.JLabel premisaMayorLabel;
    private javax.swing.JTextField premisaMenorField;
    private javax.swing.JLabel premisaMenorLabel;
    private javax.swing.JCheckBox toBARBARA_checkBox;
    private javax.swing.JCheckBox toCELARENT_checkBox;
    private javax.swing.JCheckBox toDARII_checkBox;
    private javax.swing.JCheckBox toFERIO_checkBox;
    private JButton premisaMayorSugestion;
    private JButton premisaMenorSugestion;
    private JButton conclusionSugestion;


    private javax.swing.JComboBox combo1b;
    private javax.swing.JComboBox combo2b;
    private javax.swing.JComboBox combo3b;
    private javax.swing.JTextField conclusionFieldB;
    private javax.swing.JLabel conclusionLabelB;
    private javax.swing.JLabel convertirEnLabelB;
    private javax.swing.JTextField premisaMayorFieldB;
    private javax.swing.JLabel premisaMayorLabelB;
    private javax.swing.JTextField premisaMenorFieldB;
    private javax.swing.JLabel premisaMenorLabelB;
    private javax.swing.JSeparator jSeparator1B;
    private JButton premisaMayorSugestionB;
    private JButton premisaMenorSugestionB;
    private JButton conclusionSugestionB;

    private JLabel addsPoints;
    private JLabel substractPoints;
    private JTextField addsPointsField;
    private JTextField substractPointsField;

    private int premisaLabelsStringLength;
    private ResourceBundle textBundle;

    private Sylogism sylogism;
    private Sylogism solutionSylogism;

    public SylogismReducirModosPanel() {
        this.sylogism = new Sylogism();
        premisaLabelsStringLength = 10;
        textBundle = BundlesProvider.getBundle(URLEnum.TEXT_BUNDLE);
        initComponents();
        layoutComponents();
        disableFirstPanel();
    }

    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        premisaMayorField = new javax.swing.JTextField();
        premisaMayorLabel = new javax.swing.JLabel();
        convertirEnLabel = new javax.swing.JLabel();
        combo1 = new javax.swing.JComboBox();
        premisaMenorLabel = new javax.swing.JLabel();
        premisaMenorField = new javax.swing.JTextField();
        combo2 = new javax.swing.JComboBox();
        jSeparator1 = new javax.swing.JSeparator();
        conclusionLabel = new javax.swing.JLabel();
        conclusionField = new javax.swing.JTextField();
        combo3 = new javax.swing.JComboBox();

        premisaMayorFieldB = new javax.swing.JTextField();
        premisaMayorLabelB = new javax.swing.JLabel();
        convertirEnLabelB = new javax.swing.JLabel();
        combo1b = new javax.swing.JComboBox();
        premisaMenorLabelB = new javax.swing.JLabel();
        premisaMenorFieldB = new javax.swing.JTextField();
        combo2b = new javax.swing.JComboBox();
        jSeparator1B = new javax.swing.JSeparator();
        conclusionLabelB = new javax.swing.JLabel();
        conclusionFieldB = new javax.swing.JTextField();
        combo3b = new javax.swing.JComboBox();

        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        toBARBARA_checkBox = new JCheckBox();
        toCELARENT_checkBox = new JCheckBox();
        toDARII_checkBox = new JCheckBox();
        toFERIO_checkBox = new JCheckBox();
        jScrollPane1 = new javax.swing.JScrollPane();

        addsPoints = new JLabel(textBundle.getString(TextBundleEnum.SUMA.toString()));
        substractPoints = new JLabel(textBundle.getString(TextBundleEnum.RESTA.toString()));
        addsPointsField = new JTextField(7);
        addsPointsField.setEditable(false);
        substractPointsField = new JTextField(7);
        substractPointsField.setEditable(false);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(
                new javax.swing.border.LineBorder(new java.awt.Color(204, 204, 204), 1, true),
                textBundle.getString(TextBundleEnum.SILOGISMO.toString())));

        premisaMayorFieldB.addCaretListener(new CaretListener() {
            public void caretUpdate(CaretEvent e) {
                if (Premisa.isComplete(premisaMayorFieldB.getText())) {
                    solutionSylogism.setPremisa(new Premisa(premisaMayorField.getText()), PremisaTypeEnum.FIRST);
                    premisaMayorFieldB.setForeground(new Color(0, 0, 0));
                    premisaMayorLabelB.setText(
                            Utiles.getFormattedString(textBundle.getString(
                                    TextBundleEnum.PREMISA_MAYOR.toString()), "  -  " +
                                    textBundle.getString(TextBundleEnum.EXTENSION_PARTES.toString()) + ": " +
                                    solutionSylogism.getPremisa(PremisaTypeEnum.FIRST).getTermsExtensionString()));
                    premisaMayorLabelB.setIcon(Utiles.createImageIcon(URLEnum.getReference(URLEnum.PREMISA_BREVE)));
//                    combo1.setSelectedIndex(0);
//                    enableSuggestionButtons();
                } else {
                    solutionSylogism.setPremisa(null, PremisaTypeEnum.FIRST);
                    premisaMayorFieldB.setForeground(new Color(255, 0, 0));
                    premisaMayorLabelB.setText(Utiles.getFormattedString(
                            textBundle.getString(TextBundleEnum.PREMISA_MAYOR.toString()), ""));
                    premisaMayorLabelB.setIcon(Utiles.createImageIcon(URLEnum.getReference(URLEnum.PREMISA_LARGO)));
//                    enableSuggestionButtons();
                }
            }
        });

        premisaMenorFieldB.addCaretListener(new CaretListener() {
            public void caretUpdate(CaretEvent e) {
                if (Premisa.isComplete(premisaMenorFieldB.getText())) {
                    solutionSylogism.setPremisa(new Premisa(premisaMenorFieldB.getText()), PremisaTypeEnum.SECOND);
                    premisaMenorFieldB.setForeground(new Color(0, 0, 0));
                    premisaMenorLabelB.setText(Utiles.getFormattedString(textBundle.getString(
                            TextBundleEnum.PREMISA_MENOR.toString()), "  -  " +
                            textBundle.getString(TextBundleEnum.EXTENSION_PARTES.toString()) + ": " +
                            solutionSylogism.getPremisa(PremisaTypeEnum.SECOND).getTermsExtensionString()));
                    premisaMenorLabelB.setIcon(Utiles.createImageIcon(URLEnum.getReference(URLEnum.PREMISA_BREVE)));
//                    combo2.setSelectedIndex(0);
//                    enableSuggestionButtons();
                } else {
                    solutionSylogism.setPremisa(null, PremisaTypeEnum.SECOND);
                    premisaMenorFieldB.setForeground(new Color(255, 0, 0));
                    premisaMenorLabelB.setText(Utiles.getFormattedString(
                            textBundle.getString(TextBundleEnum.PREMISA_MENOR.toString()), ""));
                    premisaMenorLabelB.setIcon(Utiles.createImageIcon(URLEnum.getReference(URLEnum.PREMISA_LARGO)));
//                    enableSuggestionButtons();
                }
            }
        });

        conclusionFieldB.addCaretListener(new CaretListener() {
            public void caretUpdate(CaretEvent e) {
                if (Premisa.isComplete(conclusionField.getText())) {
                    solutionSylogism.setPremisa(new Premisa(conclusionField.getText()), PremisaTypeEnum.CONCLUSION);
                    conclusionFieldB.setForeground(new Color(0, 0, 0));
//                    setPropertiesOrSuggestions();
                    conclusionLabelB.setText(Utiles.getFormattedString(textBundle.getString(
                            TextBundleEnum.CONCLUSION.toString()), "  -  " +
                            textBundle.getString(TextBundleEnum.EXTENSION_PARTES.toString()) + ": " +
                            solutionSylogism.getPremisa(PremisaTypeEnum.CONCLUSION).getTermsExtensionString()));
                    conclusionLabelB.setIcon(Utiles.createImageIcon(URLEnum.getReference(URLEnum.CONCLUSION_BREVE)));
                } else {
                    solutionSylogism.setPremisa(null, PremisaTypeEnum.CONCLUSION);
                    conclusionFieldB.setForeground(new Color(255, 0, 0));
//                    setPropertiesOrSuggestions();
                    conclusionLabelB.setText(Utiles.getFormattedString(
                            textBundle.getString(TextBundleEnum.CONCLUSION.toString()), ""));
                    conclusionLabelB.setIcon(Utiles.createImageIcon(URLEnum.getReference(URLEnum.CONCLUSION_LARGO)));
                }
            }
        });

        premisaMayorLabel.setText(Utiles.getFormattedString(
                textBundle.getString(TextBundleEnum.PREMISA_MAYOR.toString()), ""));
        premisaMayorLabel.setHorizontalTextPosition(SwingConstants.LEFT);
        premisaMayorLabel.setIcon(Utiles.createImageIcon(URLEnum.getReference(URLEnum.PREMISA_LARGO)));

        premisaMayorLabelB.setText(Utiles.getFormattedString(
                textBundle.getString(TextBundleEnum.PREMISA_MAYOR.toString()), ""));
        premisaMayorLabelB.setHorizontalTextPosition(SwingConstants.LEFT);
        premisaMayorLabelB.setIcon(Utiles.createImageIcon(URLEnum.getReference(URLEnum.PREMISA_LARGO)));

        convertirEnLabel.setText(textBundle.getString(TextBundleEnum.CONVERTIR_EN.toString()));
        convertirEnLabelB.setText(textBundle.getString(TextBundleEnum.CONVERTIR_EN.toString()));

        combo1.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"-", "A", "E", "I", "O"}));
        combo1b.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"-", "A", "E", "I", "O"}));
        combo1b.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                comboConvertOrComplete(PremisaTypeEnum.FIRST, combo1.getSelectedIndex(), solutionSylogism);
            }
        });

        premisaMenorLabel.setText(Utiles.getFormattedString(
                textBundle.getString(TextBundleEnum.PREMISA_MENOR.toString()), ""));
        premisaMenorLabel.setHorizontalTextPosition(SwingConstants.LEFT);
        premisaMenorLabel.setIcon(Utiles.createImageIcon(URLEnum.getReference(URLEnum.PREMISA_LARGO)));

        premisaMenorLabelB.setText(Utiles.getFormattedString(
                textBundle.getString(TextBundleEnum.PREMISA_MENOR.toString()), ""));
        premisaMenorLabelB.setHorizontalTextPosition(SwingConstants.LEFT);
        premisaMenorLabelB.setIcon(Utiles.createImageIcon(URLEnum.getReference(URLEnum.PREMISA_LARGO)));

        combo2.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"-", "A", "E", "I", "O"}));
        combo2b.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"-", "A", "E", "I", "O"}));
        combo2b.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                comboConvertOrComplete(PremisaTypeEnum.SECOND, combo2.getSelectedIndex(), solutionSylogism);
            }
        });

        jSeparator1.setForeground(new java.awt.Color(0, 0, 0));
        jSeparator1B.setForeground(new java.awt.Color(0, 0, 0));

        conclusionLabel.setText(Utiles.getFormattedString(
                textBundle.getString(TextBundleEnum.CONCLUSION.toString()), ""));
        conclusionLabel.setHorizontalTextPosition(SwingConstants.LEFT);
        conclusionLabel.setIcon(Utiles.createImageIcon(URLEnum.getReference(URLEnum.CONCLUSION_LARGO)));

        conclusionLabelB.setText(Utiles.getFormattedString(
                textBundle.getString(TextBundleEnum.CONCLUSION.toString()), ""));
        conclusionLabelB.setHorizontalTextPosition(SwingConstants.LEFT);
        conclusionLabelB.setIcon(Utiles.createImageIcon(URLEnum.getReference(URLEnum.CONCLUSION_LARGO)));

        combo3.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"-", "A", "E", "I", "O"}));
        combo3b.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"-", "A", "E", "I", "O"}));
        combo3b.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                comboConvertOrComplete(PremisaTypeEnum.CONCLUSION, combo3.getSelectedIndex(), solutionSylogism);
            }
        });

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(
                new java.awt.Color(204, 204, 204), 1, true), textBundle.getString(TextBundleEnum.FIGURA.toString())));

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(
                new java.awt.Color(204, 204, 204), 1, true), textBundle.getString(TextBundleEnum.REDUCCIONES.toString())));

        toBARBARA_checkBox.setText(textBundle.getString(TextBundleEnum.TO_BARBARA.toString()));
        toBARBARA_checkBox.setBackground(Color.WHITE);

        toCELARENT_checkBox.setText(textBundle.getString(TextBundleEnum.TO_CELARENT.toString()));
        toCELARENT_checkBox.setBackground(Color.WHITE);

        toDARII_checkBox.setText(textBundle.getString(TextBundleEnum.TO_DARII.toString()));
        toDARII_checkBox.setBackground(Color.WHITE);

        toFERIO_checkBox.setText(textBundle.getString(TextBundleEnum.TO_FERIO.toString()));
        toFERIO_checkBox.setBackground(Color.WHITE);
        setCheckBoxesSize(toFERIO_checkBox);//todo delete

        disableCheckBoxes();

        premisaMayorSugestion = new JButton(
                new PremisaSuggestionAction(PremisaTypeEnum.SECOND, PremisaTypeEnum.CONCLUSION, premisaMayorField));
//        premisaMayorSugestion.setToolTipText(textBundle.getString(TextBundleEnum.SUGERENCIA.toString()) + "...");
        premisaMayorSugestion.setEnabled(false);
        premisaMenorSugestion = new JButton(
                new PremisaSuggestionAction(PremisaTypeEnum.FIRST, PremisaTypeEnum.CONCLUSION, premisaMenorField));
//        premisaMenorSugestion.setToolTipText(textBundle.getString(TextBundleEnum.SUGERENCIA.toString()) + "...");
        premisaMenorSugestion.setEnabled(false);
        conclusionSugestion = new JButton(
                new PremisaSuggestionAction(PremisaTypeEnum.FIRST, PremisaTypeEnum.SECOND, conclusionField));
        conclusionSugestion.setEnabled(false);
//        conclusionSugestion.setToolTipText(textBundle.getString(TextBundleEnum.SUGERENCIA.toString()) + "...");

        premisaMayorSugestionB = new JButton(
                new PremisaSuggestionAction(PremisaTypeEnum.SECOND, PremisaTypeEnum.CONCLUSION, premisaMayorField));
//        premisaMayorSugestionB.setToolTipText(textBundle.getString(TextBundleEnum.SUGERENCIA.toString()) + "...");
        premisaMayorSugestionB.setEnabled(false);
        premisaMenorSugestionB = new JButton(
                new PremisaSuggestionAction(PremisaTypeEnum.FIRST, PremisaTypeEnum.CONCLUSION, premisaMenorField));
//        premisaMenorSugestionB.setToolTipText(textBundle.getString(TextBundleEnum.SUGERENCIA.toString()) + "...");
        premisaMenorSugestionB.setEnabled(false);
        conclusionSugestionB = new JButton(
                new PremisaSuggestionAction(PremisaTypeEnum.FIRST, PremisaTypeEnum.SECOND, conclusionField));
//        conclusionSugestionB.setToolTipText(textBundle.getString(TextBundleEnum.SUGERENCIA.toString()) + "...");
        conclusionSugestionB.setEnabled(false);

        sizeTextFields();
    }

    private void layoutComponents() {
        setBackground(Color.WHITE);
        setLayout(new GridBagLayout());
        createJPanel1(jPanel1, premisaMayorLabel, premisaMenorLabel, conclusionLabel,
                premisaMayorSugestion, premisaMenorSugestion, conclusionSugestion, jSeparator1, combo1,
                combo2, combo3, convertirEnLabel, premisaMayorField, premisaMenorField,
                conclusionField);
        createJPanel1(jPanel2, premisaMayorLabelB, premisaMenorLabelB, conclusionLabelB,
                premisaMayorSugestionB, premisaMenorSugestionB, conclusionSugestionB, jSeparator1B, combo1b,
                combo2b, combo3b, convertirEnLabelB, premisaMayorFieldB, premisaMenorFieldB,
                conclusionFieldB);

        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        int x = 0;
        int y = 0;
        gridBagConstraints.insets = new Insets(5, 5, 5, 5);

        layoutReducirOptions();

        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 3;
        add(jPanel1, gridBagConstraints);

        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 3;
        add(createSidePanel(), gridBagConstraints);//todo

        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;

        add(jPanel2, gridBagConstraints);
    }

    private void layoutReducirOptions() {
        jPanel3.setLayout(new GridLayout(2, 2));
        jPanel3.setMinimumSize(new Dimension(350, 89));
        jPanel3.setPreferredSize(new Dimension(350, 89));//430

        jPanel3.add(toBARBARA_checkBox);

        jPanel3.add(toCELARENT_checkBox);

        jPanel3.add(toDARII_checkBox);

        jPanel3.add(toFERIO_checkBox);
    }

    private JPanel createSidePanel() {
        JPanel panel = new JPanel(new GridBagLayout());
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridwidth = 4;
        panel.add(jPanel3, gridBagConstraints);
        gridBagConstraints.gridwidth = 1;
        gridBagConstraints.gridx = 4;
        panel.add(new JLabel(Utiles.createImageIcon(URLEnum.getReference(URLEnum.SPACE_OP))), gridBagConstraints);
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridwidth = 1;
        gridBagConstraints.gridy = 0;
        panel.add(createScoringPanel(), gridBagConstraints);
        panel.setBackground(Color.WHITE);
        return panel;
    }

    private void setCheckBoxesSize(JCheckBox checkBox) {
        checkBox.setPreferredSize(new Dimension(150, 25));
    }

    private void createJPanel1(JPanel panel, JLabel premisaMayorLabel,
                               JLabel premisaMenorLabel, JLabel conclusionLabel,
                               JButton premisaMayorSugestion, JButton premisaMenorSugestion,
                               JButton conclusionSugestion, JSeparator separator, JComboBox combo1,
                               JComboBox combo2, JComboBox combo3, JLabel convertirEnLabel,
                               JTextField premisaMayorField, JTextField premisaMenorField,
                               JTextField conclusionField) {
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        int x = 0;
        int y = 0;
        gridBagConstraints.insets = new Insets(5, 5, 5, 5);
        panel.setLayout(new GridBagLayout());

        /*      PREMISAS     */
        panel.add(premisaMayorLabel, gridBagConstraints);

        gridBagConstraints.gridx = (x += 7);
        panel.add(convertirEnLabel, gridBagConstraints);

        gridBagConstraints.gridx = (x -= 7);
        gridBagConstraints.gridy = ++y;
        gridBagConstraints.gridwidth = 5;
        panel.add(premisaMayorField, gridBagConstraints);

        gridBagConstraints.gridwidth = 1;
        gridBagConstraints.gridx = (x += 6);

        panel.add(premisaMayorSugestion, gridBagConstraints);

        gridBagConstraints.gridx = (x += 1);
        panel.add(combo1, gridBagConstraints);

        gridBagConstraints.gridx = (x -= 7);
        gridBagConstraints.gridy = ++y;
        panel.add(premisaMenorLabel, gridBagConstraints);

        gridBagConstraints.gridwidth = 5;
        gridBagConstraints.gridy = ++y;
        panel.add(premisaMenorField, gridBagConstraints);

        gridBagConstraints.gridwidth = 1;
        gridBagConstraints.gridx = (x += 6);

        panel.add(premisaMenorSugestion, gridBagConstraints);

        gridBagConstraints.gridx = (x += 1);
        panel.add(combo2, gridBagConstraints);

        gridBagConstraints.gridwidth = 7;
        gridBagConstraints.gridx = (x -= 7);
        gridBagConstraints.gridy = ++y;
        separator.setPreferredSize(new Dimension(550, 2));
        panel.add(separator, gridBagConstraints);

        gridBagConstraints.gridwidth = 1;
        gridBagConstraints.gridy = ++y;
        panel.add(conclusionLabel, gridBagConstraints);

        gridBagConstraints.gridy = ++y;
        gridBagConstraints.gridwidth = 5;
        panel.add(conclusionField, gridBagConstraints);

        gridBagConstraints.gridwidth = 1;
        gridBagConstraints.gridx = (x += 6);

        panel.add(conclusionSugestion, gridBagConstraints);

        gridBagConstraints.gridx = (x += 1);
        panel.add(combo3, gridBagConstraints);

        panel.setMinimumSize(new Dimension(655, 250));
        panel.setPreferredSize(new Dimension(655, 250));
    }

    private JPanel createScoringPanel() {
        JPanel scoringPanel = new JPanel();
        scoringPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLACK),
                textBundle.getString(TextBundleEnum.PUNTAJE.toString())));
        scoringPanel.setLayout(new GridBagLayout());
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.insets = new Insets(5, 5, 5, 5);
        scoringPanel.add(addsPoints, gridBagConstraints);
        gridBagConstraints.gridx = 1;
        scoringPanel.add(addsPointsField, gridBagConstraints);
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridx = 0;
        scoringPanel.add(substractPoints, gridBagConstraints);
        gridBagConstraints.gridx = 1;
        scoringPanel.add(substractPointsField, gridBagConstraints);
        scoringPanel.setBackground(Color.WHITE);
        return scoringPanel;
    }

    private void sizeTextFields() {
        premisaMayorField.setColumns(45);
        premisaMayorField.setMinimumSize(new Dimension(550, 20));
        premisaMenorField.setColumns(45);
        premisaMenorField.setMinimumSize(new Dimension(550, 20));
        conclusionField.setColumns(45);
        conclusionField.setMinimumSize(new Dimension(550, 20));

        premisaMayorFieldB.setColumns(45);
        premisaMayorFieldB.setMinimumSize(new Dimension(550, 20));
        premisaMenorFieldB.setColumns(45);
        premisaMenorFieldB.setMinimumSize(new Dimension(550, 20));
        conclusionFieldB.setColumns(45);
        conclusionFieldB.setMinimumSize(new Dimension(550, 20));
    }

    private void uncheckAllCheckBoxes() {
        toBARBARA_checkBox.setSelected(false);
        toCELARENT_checkBox.setSelected(false);
        toDARII_checkBox.setSelected(false);
        toFERIO_checkBox.setSelected(false);
    }

    private void reset() {
        sylogism = new Sylogism();
        premisaMayorField.setText("");
        premisaMenorField.setText("");
        conclusionField.setText("");
//        setPropertiesOrSuggestions();
    }

    public void comboConvertOrComplete(PremisaTypeEnum premisaTypeEnum, int selectedIndex, Sylogism sylogism) {
        if (sylogism.getPremisa(premisaTypeEnum) != null) {
            switch (selectedIndex) {
                case 1://A
                    sylogism.getPremisa(premisaTypeEnum).convert(ExtensionEnum.A);
                    break;
                case 2://E
                    sylogism.getPremisa(premisaTypeEnum).convert(ExtensionEnum.E);
                    break;
                case 3://I
                    sylogism.getPremisa(premisaTypeEnum).convert(ExtensionEnum.I);
                    break;
                case 4://O
                    sylogism.getPremisa(premisaTypeEnum).convert(ExtensionEnum.O);
                    break;
                case 0://no hace nada
                    break;
            }
            switch (premisaTypeEnum) {
                case FIRST:
                    premisaMayorFieldB.setText(sylogism.getPremisa(premisaTypeEnum).toString());
                    break;
                case SECOND:
                    premisaMenorFieldB.setText(sylogism.getPremisa(premisaTypeEnum).toString());
                    break;
                case CONCLUSION:
                    conclusionFieldB.setText(sylogism.getPremisa(premisaTypeEnum).toString());
                    break;
            }
        }
    }

    public void setSylogism(Sylogism sylogism) {
        this.sylogism = sylogism;
        if (sylogism.getPremisa(PremisaTypeEnum.FIRST) != null) {
            premisaMayorField.setText(sylogism.getPremisa(PremisaTypeEnum.FIRST).toString());
        }
        if (sylogism.getPremisa(PremisaTypeEnum.SECOND) != null) {
            premisaMenorField.setText(sylogism.getPremisa(PremisaTypeEnum.SECOND).toString());
        }
        if (sylogism.getPremisa(PremisaTypeEnum.CONCLUSION) != null) {
            conclusionField.setText(sylogism.getPremisa(PremisaTypeEnum.CONCLUSION).toString());
        }
        uncheckAllCheckBoxes();
        switch (sylogism.getReduceMode()) {
            case BARBARA:
                toBARBARA_checkBox.setSelected(true);
                break;
            case CELARENT:
                toCELARENT_checkBox.setSelected(true);
                break;
            case DARII:
                toDARII_checkBox.setSelected(true);
                break;
            case FERIO:
                toFERIO_checkBox.setSelected(true);
                break;
            case UNKNOWN:
                //todo ver como se trata el caso!
                break;
        }
    }

    public void setSolutionSylogism(Sylogism sylogism) {
        this.solutionSylogism = sylogism;                       //todo
        if (sylogism.getPremisa(PremisaTypeEnum.FIRST) != null) {
            premisaMayorFieldB.setText(sylogism.getPremisa(PremisaTypeEnum.FIRST).toString());
        } else {
            premisaMayorFieldB.setText("");
        }
        if (sylogism.getPremisa(PremisaTypeEnum.SECOND) != null) {
            premisaMenorFieldB.setText(sylogism.getPremisa(PremisaTypeEnum.SECOND).toString());
        } else {
            premisaMenorFieldB.setText("");
        }
        if (sylogism.getPremisa(PremisaTypeEnum.CONCLUSION) != null) {
            conclusionFieldB.setText(sylogism.getPremisa(PremisaTypeEnum.CONCLUSION).toString());
        } else {
            conclusionFieldB.setText("");
        }
    }

    private void disableFirstPanel() {
        premisaMayorSugestion.setEnabled(false);
        combo1.setEnabled(false);
        premisaMenorSugestion.setEnabled(false);
        combo2.setEnabled(false);
        conclusionSugestion.setEnabled(false);
        combo3.setEnabled(false);

        premisaMayorField.setEditable(false);
        premisaMenorField.setEditable(false);
        conclusionField.setEditable(false);
        //todo complete
    }

    public TestExcercise getExercise() throws ExerciseNotBuiltException, PunctuationZeroException {
        System.out.println(""+solutionSylogism);
        
        solutionSylogism.setPremisa(new Premisa(premisaMayorFieldB.getText()), PremisaTypeEnum.FIRST);
        solutionSylogism.setPremisa(new Premisa(premisaMenorFieldB.getText()), PremisaTypeEnum.SECOND);
        solutionSylogism.setPremisa(new Premisa(conclusionFieldB.getText()), PremisaTypeEnum.CONCLUSION);
        System.out.println(""+solutionSylogism);
        System.out.println(""+solutionSylogism.getReduceMode());
        if (!solutionSylogism.isComplete() || addsPointsField.getText().equals("") ||
                substractPointsField.getText().equals("")) {
            throw new ExerciseNotBuiltException();
        }
        if (Integer.parseInt(addsPointsField.getText()) == 0) {
            throw new PunctuationZeroException();
        }
        testExercise.setStudentsSolution(solutionSylogism);
        return testExercise;
    }

    public void setExercise(TestExcercise testExerciseData) {
        testExercise = testExerciseData;
        setSylogism((Sylogism) testExercise.getExcerciseData());
        System.out.println("----"+testExercise.getStudentsSolution());//todo
        setSolutionSylogism((Sylogism) testExercise.getStudentsSolution());
        addsPointsField.setText("" + testExercise.getCorrectScore());
        substractPointsField.setText("" + testExercise.getIncorrectScore());
    }

    class PremisaSuggestionAction extends AbstractAction {
        private PremisaTypeEnum first;
        private PremisaTypeEnum second;
        private JTextField newPremisaField;

        public PremisaSuggestionAction(PremisaTypeEnum first, PremisaTypeEnum second, JTextField newPremisaField) {
            super("", Utiles.createImageIcon(URLEnum.getReference(URLEnum.LIGHT_BULB)));
            this.first = first;
            this.second = second;
            this.newPremisaField = newPremisaField;
        }

        public void actionPerformed(ActionEvent e) {
            Premisa firstPremisa = sylogism.getPremisa(first);
            Premisa secondPremisa = sylogism.getPremisa(second);

            if (firstPremisa != null && secondPremisa != null) {
                if (Utiles.getRandomInt(2) == 1) {
                    newPremisaField.setText(Premisa.getRandomPremisa(firstPremisa).toString());
                } else {
                    newPremisaField.setText(Premisa.getRandomPremisa(secondPremisa).toString());
                }
            } else {
                if (firstPremisa != null) {
                    newPremisaField.setText(Premisa.getRandomPremisa(firstPremisa).toString());
                } else {
                    if (secondPremisa != null) {
                        newPremisaField.setText(Premisa.getRandomPremisa(secondPremisa).toString());
                    } else {
                        newPremisaField.setText(Premisa.getRandomPremisa().toString());
                    }
                }
            }
        }
    }

    private void disableCheckBoxes() {
        toBARBARA_checkBox.setEnabled(false);
        toCELARENT_checkBox.setEnabled(false);
        toDARII_checkBox.setEnabled(false);
        toFERIO_checkBox.setEnabled(false);
    }

    private void enableSuggestionButtons() {
        if (sylogism.isComplete()) {
            premisaMayorSugestion.setEnabled(false);
            premisaMenorSugestion.setEnabled(false);
            conclusionSugestion.setEnabled(false);
        } else {
            premisaMayorSugestion.setEnabled(true);
            premisaMenorSugestion.setEnabled(true);
            conclusionSugestion.setEnabled(true);
        }
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("SilogismoPanel");
        frame.setContentPane(new SylogismReducirModosPanel());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
}
